import tkinter as tk
import tkinter.font as tkFont
import tkinter.messagebox as tkMsgBox

top=tk.Tk()
top.resizable(False, False)
top.title("King_haoqi的问卷")
top.configure()
gf = tkFont.Font(top, size = 15)

####   A   ####### 
aFrame=tk.Frame(top)
aFrame.pack(side = tk.TOP, fill=tk.X, padx = 6, pady=6)

a1 = tk.BooleanVar()
a2 = tk.BooleanVar()
a3 = tk.BooleanVar()
a4 = tk.BooleanVar()

a_text=tk.Label(aFrame,text="1.King_haoqi是(  ) [多选]",font=gf)
a_text.pack(side=tk.TOP)
a_1 = tk.Checkbutton(aFrame, text="A.天才", variable=a1, offvalue=False, onvalue=True,font=gf)
a_1.pack(side=tk.LEFT)
a_2 = tk.Checkbutton(aFrame, text="B.天生的蠢才", variable=a2, offvalue=False, onvalue=True,font=gf)
a_2.pack(side=tk.LEFT)
a_3 = tk.Checkbutton(aFrame, text="C.圣人", variable=a3, offvalue=False, onvalue=True,font=gf)
a_3.pack(side=tk.LEFT)
a_4 = tk.Checkbutton(aFrame, text="D.圣洁的死人", variable=a4, offvalue=False, onvalue=True,font=gf)
a_4.pack(side=tk.LEFT)

####   B   ####### 
bFrame=tk.Frame(top)
bFrame.pack(side = tk.TOP, fill=tk.X, padx = 6, pady=6)

b1 = tk.BooleanVar()
b2 = tk.BooleanVar()
b3 = tk.BooleanVar()
b4 = tk.BooleanVar()

b_text=tk.Label(bFrame,text="2.King_haoqi很(  ) [多选]",font=gf)
b_text.pack(side=tk.TOP)
b_1 = tk.Checkbutton(bFrame, text="A.牛", variable=b1, offvalue=False, onvalue=True,font=gf)
b_1.pack(side=tk.LEFT)
b_2 = tk.Checkbutton(bFrame, text="B.蠢", variable=b2, offvalue=False, onvalue=True,font=gf)
b_2.pack(side=tk.LEFT)
b_3 = tk.Checkbutton(bFrame, text="C.帅", variable=b3, offvalue=False, onvalue=True,font=gf)
b_3.pack(side=tk.LEFT)
b_4 = tk.Checkbutton(bFrame, text="D.富", variable=b4, offvalue=False, onvalue=True,font=gf)
b_4.pack(side=tk.LEFT)

##### C #######
cFrame=tk.Frame(top)
cFrame.pack(side = tk.TOP, fill=tk.X, padx = 6, pady=6)

ansc=tk.IntVar()
ansc.set(0)

c_text=tk.Label(cFrame,text="3.King_haoqi十分(  ) [单选]",font=gf)
c_text.pack(side=tk.TOP)

c_1=tk.Radiobutton(cFrame, text="A.残忍", variable=ansc, value=1,font=gf)
c_1.pack(side=tk.LEFT)
c_2=tk.Radiobutton(cFrame, text="B.邪恶", variable=ansc, value=2,font=gf)
c_2.pack(side=tk.LEFT)
c_3=tk.Radiobutton(cFrame, text="C.仁慈", variable=ansc, value=3,font=gf)
c_3.pack(side=tk.LEFT)
c_4=tk.Radiobutton(cFrame, text="D.令人厌恶", variable=ansc, value=4,font=gf)
c_4.pack(side=tk.LEFT)

##### D #######
dFrame=tk.Frame(top)
dFrame.pack(side = tk.TOP, fill=tk.X, padx = 6, pady=6)

ansd=tk.IntVar()
ansd.set(0)

d_text=tk.Label(dFrame,text="4.King_haoqi不是一个(  )的人 [单选]",font=gf)
d_text.pack(side=tk.TOP)

d_1=tk.Radiobutton(dFrame, text="A.可亲", variable=ansd, value=1,font=gf)
d_1.pack(side=tk.LEFT)
d_2=tk.Radiobutton(dFrame, text="B.令人喜爱", variable=ansd, value=2,font=gf)
d_2.pack(side=tk.LEFT)
d_3=tk.Radiobutton(dFrame, text="C.编程技术高超", variable=ansd, value=3,font=gf)
d_3.pack(side=tk.LEFT)
d_4=tk.Radiobutton(dFrame, text="D.没有情感", variable=ansd, value=4,font=gf)
d_4.pack(side=tk.LEFT)

ans=False

def OnOK():
    global ans
    mark=0
    if not (a1.get() or a2.get() or a3.get() or a4.get()):
        tkMsgBox.showerror('error', "你还未作答第一题")
        return
    elif [a1.get(),a2.get(),a3.get(),a4.get()]==[True,False,True,False]:
        mark+=1
    if not (b1.get() or b2.get() or b3.get() or b4.get()):
        tkMsgBox.showerror('error', "你还未作答第二题")
        return
    elif [b1.get(),b2.get(),b3.get(),b4.get()]==[True,False,True,True]:
        mark+=1
    if ansc.get()==0:
        tkMsgBox.showerror('error', "你还未作答第三题")
        return
    elif ansc.get()==3:
        mark+=1
    if ansd.get()==0:
        tkMsgBox.showerror('error', "你还未作答第四题")
        return
    elif ansd.get()==4:
        mark+=1
    tkMsgBox.showinfo('score', "你答对了"+str(mark)+"题")
    ans=True

def show_ans():
    if ans==False:
        tkMsgBox.showerror('error', "请作答完毕并提交后再查看解析")
        return
    at=tk.Tk()
    at.resizable(False, False)
    at.title("King_haoqi的问卷解析")
    wf = tkFont.Font(top, size = 15)
    l1=tk.Label(at,text="1.A C [解析]堂堂King_haoqi怎么可能蠢?!怎么可能死了?!",font=wf,padx=7,pady=2)
    l1.pack(side=tk.TOP)
    l2=tk.Label(at,text='2.A C D [解析]因为沃兹基说过:"这世上集牛,帅,富于一体的人,唯有King_haoqi"所以选ACD',font=wf,padx=7,pady=2)
    l2.pack(side=tk.TOP)
    l3=tk.Label(at,text="3.C [解析]世上最仁慈的人,无疑是King_haoqi!",font=wf,padx=7,pady=2)
    l3.pack(side=tk.TOP)
    l4=tk.Label(at,text="4.D [解析]啊,King_haoqi!你是世上最富有情感的人!",font=wf,padx=7,pady=2)
    l4.pack(side=tk.TOP)

btnFrame=tk.Frame(top)
btnFrame.pack(side = tk.TOP, fill=tk.X, padx = 6, pady=6)

btn = tk.Button(btnFrame, text='提交答案', command=OnOK,font=gf)
btnans=tk.Button(btnFrame,text='查看解析',command=show_ans,font=gf)

btn.pack()
btnans.pack(side=tk.RIGHT)

top.mainloop()